package com.boot.security.server.controller.system;

import java.util.List;

import com.boot.security.server.controller.mffl.MfflConsultation.Clinet_MfflConsultationController;
import com.boot.security.server.model.mffl.Vo.OrderVo;
import com.boot.security.server.service.impl.mffl.MfflConsultation.MfflConsultationService;
import com.boot.security.server.service.impl.mffl.MfflContract.MfflContractService;
import com.boot.security.server.service.impl.mffl.MfflImageAndText.MfflImageAndTextService;
import com.boot.security.server.service.impl.mffl.MfflLawyerletter.MfflLawyerletterService;
import com.boot.security.server.service.impl.mffl.MfflOrder.MfflOrderService;
import com.boot.security.server.utils.mffl.MfflServiceEnum;
import com.boot.security.server.utils.mffl.ReturnBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.dao.mffl.MfflOrderDao;
import com.boot.security.server.model.mffl.MfflOrder;

import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@RestController
@RequestMapping("/mfflOrders")
public class MfflOrderController {

    @Autowired
    private MfflOrderDao mfflOrderDao;

    @PostMapping
    @ApiOperation(value = "保存")
    @PreAuthorize("hasAnyAuthority('sys:orders:add')")
    public MfflOrder save(@RequestBody MfflOrder mfflOrder) {
        mfflOrderDao.save(mfflOrder);

        return mfflOrder;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    @PreAuthorize("hasAnyAuthority('sys:orders:query')")
    public MfflOrder get(@PathVariable Long id) {
        return mfflOrderDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    @PreAuthorize("hasAnyAuthority('sys:orders:add')")
    public MfflOrder update(@RequestBody MfflOrder mfflOrder) {
        mfflOrderDao.update(mfflOrder);
        return mfflOrder;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    @PreAuthorize("hasAnyAuthority('sys:orders:query')")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return mfflOrderDao.orderCount(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<OrderVo> list(PageTableRequest request) {
                return mfflOrderDao.orderList(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @GetMapping(value = "/award")
    @ApiOperation(value = "列表")
    @PreAuthorize("hasAnyAuthority('sys:orders:query')")
    public PageTableResponse awardList(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return mfflOrderDao.awardCount(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<OrderVo> list(PageTableRequest request) {
                return mfflOrderDao.awardList(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    @PreAuthorize("hasAnyAuthority('sys:orders:del')")
    public void delete(@PathVariable Long id) {
        MfflOrder mfflOrder = this.mfflOrderDao.getById(id);
        String str = MfflServiceEnum.getDescriptionByType(mfflOrder.getServierId());

    }



    @Autowired
    private MfflOrderService mfflOrderService;


    @PostMapping("/updateOrderState")
    @ApiOperation(value = "修正订单状态")
    @PreAuthorize("hasAnyAuthority('sys:orders:del')")
    public ReturnBean updateOrderState() throws Exception {
        return this.mfflOrderService.updateOrderState();
    }


}
